import request from "../utils/requset";

const enum Api {
  // 获取购物车数据
  getShoppingCart = "/user/shoppingCart/getShoppingCart",
  // 删除购物车数据
  delShoppingCart = "/user/shoppingCart/deleteShoppingCart",
  //更新购物车商品数量
  updateShoppingCart = "/user/shoppingCart/updateShoppingCart",
}

/**
 *
 * @param user_id
 * @returns // 获取购物车列表
 */
export interface Response {
  code: string;
  shoppingCartData: GetShoppingCartList;
}
export type GetShoppingCartList = GetShoppingCart[];
export interface GetShoppingCart {
  id: number;
  productID: number;
  productName: string;
  productImg: string;
  price: number;
  num: number;
  maxNum: number;
  check: boolean;
}
export const getShoppingCartApi = (user_id: number) => {
  return request.post<any, Response>(Api.getShoppingCart, {
    user_id,
  });
};

/**
 *
 * @param user_id
 * @param product_id
 * @returns // 删除购物车数据
 */
export const delShoppingCartApi = (user_id: number, product_id: number) => {
  return request.post(Api.delShoppingCart, {
    user_id,
    product_id,
  });
};

//更新购物车商品数量

export const updateShoppingCartApi = (data:{
  user_id: number;
  product_id: number;
  num: number;
}) => {
  return request.post(Api.updateShoppingCart, data);
};
